package university;
import university.exceptions.*;
import java.util.*;

/**
 * Class that describes tests for Students
 * @author anatolii.bondarenko
 */
class TakeATest extends KnowledgeControl {
    private Group group;
    private List<Student> failedStudents;
    /**
     * Details of test
     * @param d is discipline of test(teacher is taken from discipline class)
     * @param gr is group that will take the test
     * @param ev is time and place of test
     */
    public TakeATest(Discipline d,Group gr, ExamEvent ev) throws GroupGraduatedException{
		super(d,ev);
		group = gr;
        if (gr.isGraduated() == true){
            throw new GroupGraduatedException("Cannot examine already graduated group");
        }
		failedStudents = new ArrayList<Student>(0);
	}

    /**
     * Constructor that is used for test retries
     * @param d is discipline of test(teacher is taken from discipline class)
     * @param ev is time and place of test
     */
    public TakeATest (Discipline d, ExamEvent ev){
		super(d,ev);
	}

    /**
     * Gets details of test in string format
     * @return details of test
     */
    public String toString(){
		return "Test " + super.getDiscipline() + super.getTimeAndPlace() + ". Teacher: "
				+ super.getTeacher() + ". Group " + group.getGroupName()+".";
	}
    /**
     * If student fails the test his number of failed disciplines is raised by 1 and he is added to the list of students that failed
     * @param s
     */
    public void fail(Student s)throws NoElementInListException, ExamineResignedStudentException, NoFailedDisciplinesException{
        if (!group.getListOfStudents().contains(s)){
            throw new NoElementInListException("No such student in this group");
        }
        if (s.isResigned()){
            throw new ExamineResignedStudentException("Cannot examine resigned students");
        }
		s.addFailedDiscipline();
		failedStudents.add(s);
	}

    /**
     * Gets the list of students that failed the test
     * @return List of students that failed the test
     */
    public List<Student> getListOfFailedStudents(){
		return failedStudents;
	}

    /**
     * Gets the group that will take a test
     * @return the group that will take a test
     */
    public Group getGroup(){
        return group;
    }
	

}
